#include "SceneInstruction.h"
#include "sprite.h"
#include "SoundEffectHandler.h"

SceneInstruction::SceneInstruction(Renderer* renderer)
    : Scene(renderer), m_elapsedTime(0.0f) {
    m_x = m_width;
    m_y = 100;
}

SceneInstruction::~SceneInstruction() {
    delete m_logoSprite;
}

void SceneInstruction::Initialize() {
    // load game logo
    m_logoSprite[0] = m_renderer->CreateSprite("asset/tank_logo/1.png");
    m_logoSprite[1] = m_renderer->CreateSprite("asset/tank_logo/2.png");
    m_logoSprite[2] = m_renderer->CreateSprite("asset/tank_logo/3.png");
    m_logoSprite[3] = m_renderer->CreateSprite("asset/tank_logo/tank_logo.png");
    m_logoSprite[3]->SetScale(0.5);
    SoundEffectHandler::Instance()->PlayInstruction();
}

void SceneInstruction::Update(float deltaTime) {
    m_elapsedTime += deltaTime;
    if (m_x > m_width / 2) {
        m_x-=3;
    }
    else if(!m_bPaused){
        SoundEffectHandler::Instance()->PauseInstruction();
        SoundEffectHandler::Instance()->PlayLogo();
        m_bPaused = true;
    }
}

void SceneInstruction::Render() {
    
    if (m_bPaused) {
        index = 3;
        m_renderer->RenderText("ATTACKING!", m_width/2, m_height/3, { 255,255,255,240 }, true);


        m_renderer->RenderText("MOVE: W,A,S,D", m_width / 2-300, m_height / 2 , { 255,255,255,240 });
        m_renderer->RenderText("SHOOT: UP, DOWN, LEFT, RIGHT", m_width / 2+300, m_height / 2 , { 255,255,255,240 });

        m_renderer->RenderText("PRESS SPACE TO CONTINUE", m_width / 2, m_height / 2 + 100, { 255,255,255,240 });
        m_renderer->RenderText("PRESS ESC TO QUIT", m_width/2, m_height/2+150, { 255,255,255,240 });
    }
    m_logoSprite[index]->SetX(m_x);
    m_logoSprite[index]->SetY(m_y);
    m_logoSprite[index]->Draw(*m_renderer);
    index++;
    index %= 3;

}

bool SceneInstruction::Finished() {
    return m_elapsedTime >= INSTRUCTION_TIME;
}